package com.wb3.organizer.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.wb3.organizer.dao.TaskDAO;
import com.wb3.organizer.model.Account;
import com.wb3.organizer.model.Task;

public class TaskDAOImpl implements TaskDAO {

	private HibernateTemplate ht;

	public HibernateTemplate getHt() {
		return ht;
	}

	public void setHt(HibernateTemplate ht) {
		this.ht = ht;
	}

	public void save(Task task) {
		ht.save(task);
	}

	public void update(Task task) {
		ht.update(task);
	}

	public void delete(Task task) {
		ht.delete(task);
	}

	@SuppressWarnings("unchecked")
	public List<Task> getAllByAccount(Account account) {
		List<Task> tasks = ht.find("from Task t where t.account = ?", account);
		return tasks;
	}

	public Task getTaskById(int task_id) {
		return ht.get(Task.class, task_id);
	}

}
